package io;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @author liyang
 * @version 1.0
 * @package io
 * @file CopyDemo2.java
 * @description
 * @time 2024-03-20 23:23
 */
public class CopyDemo2 {
    public static void main(String[] args) throws IOException {
/**
 * 此时如果把照片换成更大的文件，就会发现传输速度明显变快了
  */
        FileInputStream fis = new FileInputStream("./image.png");
        FileOutputStream fos = new FileOutputStream("./image_cp.png");
        byte[] data = new byte[1024 * 10];
        int len;//记录每次实际读取到的字节数
        //计时语句
        long start = System.currentTimeMillis();
        while ((len = fis.read(data)) != -1) {
            fos.write(data,0,len);
        }
        long end = System.currentTimeMillis();
        System.out.println("复制完毕,耗时:" + (end - start) + "ms");
        fis.close();
        fos.close();
    }
}
